// 草稿管理
export const state = () => ({
    draftList:[]
});

export const mutations = {
    setDraftInfo(state,data){
        // 判断大于等于五个记录就删除最后面一个
        // 使历史记录一直保持五个
        if(state.draftList.length >= 10){
            state.draftList.pop();
        }
        // 将最新的历史记录放在最前端
        state.draftList.unshift(data);
    },
    updateDraftInfo(state,data){
        for(let i=0;i<state.draftList.length;i++){
            if(state.draftList[i].id == data.id){
                state.draftList[i].title = data.title;
                state.draftList[i].content = data.content;
                state.draftList[i].city = data.city;
                state.draftList[i].date = data.date;
                break;
            }
        }
    },
    delDraftInfo(state,data){
        for(let i=0;i<state.draftList.length;i++){
            if(state.draftList[i].id == data){
                state.draftList.splice(i,1);
                break;
            }
        }
    }
}